package com.yuyou.fn.electronicinvoice.service.impl;

import com.github.wens.framework.service.impl.SuperServiceImpl;
import com.github.wens.mybatisplus.examples.Example;
import com.github.wens.mybatisplus.toolkit.IdWorker;
import com.yuyou.fn.common.util.TimeUtils;
import com.yuyou.fn.electronicinvoice.entity.RecordTempInvoice;
import com.yuyou.fn.electronicinvoice.mapper.RecordTempInvoiceMapper;
import com.yuyou.fn.electronicinvoice.service.IRecordTempInvoiceService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 *
 * RecordTempInvoice 表数据服务层接口实现类
 *
 */
@Service
public class RecordTempInvoiceServiceImpl extends SuperServiceImpl<RecordTempInvoiceMapper, RecordTempInvoice,Long> implements IRecordTempInvoiceService {
    @Override
    public RecordTempInvoice findOrCreateByObjectId(Long objectId,Integer status,Integer invoiceType,String objectType) {
        Example<RecordTempInvoice> example=RecordTempInvoice.createExample();
        example.createCriteria().andEqualTo("objectId",objectId).andEqualTo("status",status).andEqualTo("invoiceType",invoiceType).andEqualTo("objectType",objectType);
        RecordTempInvoice recordTempInvoice=this.findOneByExample(example);
        if (recordTempInvoice==null){
            recordTempInvoice=new RecordTempInvoice();
            recordTempInvoice.setObjectId(objectId);
            recordTempInvoice.setCreateTime(TimeUtils.now());
            recordTempInvoice.setUpdateTime(TimeUtils.now());
            recordTempInvoice.setStatus(status);
            recordTempInvoice.setInvoiceType(invoiceType);
            recordTempInvoice.setRecordTempInvoiceId(IdWorker.getId());
            recordTempInvoice.setObjectType(objectType);
            this.insert(recordTempInvoice);
        }
        return recordTempInvoice;
    }

    @Override
    public List<RecordTempInvoice> findUnDealRecordOrderByInvoiceType() {
        Example<RecordTempInvoice> example=RecordTempInvoice.createExample();
        example.createCriteria().andEqualTo("status",1);
        example.orderBy("invoiceType").desc();
        return this.findListByExample(example);
    }
}